package com.superhelper.receiver.utils;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

public class HttpUtil {

    public static Map<String, Object> toMap(HttpServletRequest request) {
        Map<String, Object> result = new HashMap<>();
        Enumeration<String> names = request.getParameterNames();
        while (names.hasMoreElements()) {
            String name = names.nextElement();
            String[] values = request.getParameterValues(name);
            if (values == null || values.length == 0) {
                continue;
            }
            if (values.length == 1) {
                result.put(name, values[0]);
            } else {
                result.put(name, values);
            }
        }
        return result;
    }

}
